<#assign menu="system">
<#assign submenu="system_basic">
<#include "/system/head.ftl">
<!--main content start-->
<section id="main-content">
	<section class="wrapper">
    	<!-- page start-->
    	<div class="row">
		<div class="col-lg-12">
		<section class="panel">
			<header class="panel-heading">
					发送内部邮件给会员
			</header>
				<form id="userEmailForm" action="" role="form" class="form-horizontal" autocomplete="off" method="post" >
			<div class="panel-body">
					<div class="form-group">
						<label class="col-lg-2 col-sm-2 control-label" for="inputEmail1">收件人</label>
						<div class="col-lg-10">
							<label class="radio-inline">
                        		<input type="radio" name="isSendToAllUser" value="1" checked/>所有人
                      		</label>
                      		<label class="radio-inline">
                        		<input type="radio" name="isSendToAllUser" value="0" />单个会员
                      		</label>
							<input type="text" placeholder="收件人" id="acceptUserName" name="userWebEmail.acceptUserName"
								class="form-control" value="">
						</div>
					</div>
					<div class="form-group">
						<label class="col-lg-2 col-sm-2 control-label" for="inputEmail1">标题</label>
						<div class="col-lg-10">
							<input type="text" placeholder="标题" id="title" name="userWebEmail.title"
								class="form-control" value="">
						</div>
					</div>
					<div class="form-group">
                          <label class="col-sm-2 col-sm-2 control-label">邮件内容</label>
                          <div class="col-sm-10">
                              <script id="content" name="content" type="text/plain"
									style="width: 100%; height: 260px;"></script>
							  <script type="text/javascript">
								var contentEditor;
								$(function() {
									contentEditor = UE.getEditor('content');
								});
							  </script>
                          </div>
                    </div>
                  </div>
                  
					<div class="form-group">
						<div class="col-lg-offset-2 col-lg-10">
							<button class="btn btn-danger" type="submit">发送</button>
						</div>
					</div>
				</form>
			</div>
		</section>
	</div>
	</div>
    	<!-- page end-->
     </section>
</section>
<!--main content end-->

<script type="text/javascript">

function ajaxSubmit(){  
    if( $("#userEmailForm").valid()){  
       $.ajax(
		{
			url:"${basePath}/admin/userWebEmail/sendEmail.json",
			type:"post",
			data:$("#userEmailForm").serialize(),
			dataType:"json",
			success:function(data){
				if (data.result) {
					bootbox.alert("保存成功，将刷新页面", function() {
						window.location.reload();
					});					
				}else{
					showErrors($('#userEmailForm'),data.errors);
				}
			},
			error:function(XMLHttpRequest, textStatus, errorThrown){
				bootbox.alert({  
		            buttons: {  
		               ok: {  
		                    label: '关闭'
		               }  
		            },  
		            message: XMLHttpRequest.responseText,
		            title: "错误",  
		        });
			}
		});
    }  
}
$().ready(function() {
 $("#userEmailForm").validate({
        rules: {
		   title: {
					required: true
			}
		 },
        messages: {
		   title: {
					required: "请输入标题"
				}
		},   
        submitHandler: function(form) {  
            //alert('要提交了!');  
            //1. 不可用 $(form).submit();否则会死循环  
            //2. 如果 form.submit()也不用，此表单就不会自动提交了  
            //form.submit();  
            //3. 下面是 ajax 提交  
            ajaxSubmit();  
        } 
    });
});
</script>

<#include "/system/foot.ftl">